# 测试估值函数
import chess
from src.chess_util import Chess

my_chess = Chess()

fen_dict = [
    {
        'id': 1,
        'name': '叠兵数量测试',
        'fen': ['rnbqkbnr/ppp4p/6p1/3Pp3/2P3p1/5N2/PP1P1P1P/RNBQKB1R w KQkq - 0 6',
                'rnbqkbnr/pp1p1ppp/3p4/3p4/3P4/3P4/PP1P1PPP/RNBQKBNR w KQkq - 0 1']
    },
    {
        'id': 2,
        'name': '局面进程判断',
        'fen': ['rnbqkbnr/ppp1pppp/8/3P4/8/8/PPP1PPPP/RNBQKBNR w KQkq - 0 1',
                'r1bqkbnr/ppp3pp/8/2nPp3/8/2Np4/PPP1PPPP/R1BQK2R w KQkq - 0 1',
                'r1b1kbnr/ppp3pp/8/2nPp3/8/2Np4/PPP1PPPP/R1BQK2R w KQkq - 0 1']
    },
    {
        'id': 3,
        'name': '通路兵',
        'fen': ['k7/5ppp/8/8/8/8/P1P1P3/1K6 w - - 0 1',
                'k7/5ppp/8/2P5/8/2p5/P3P3/1K6 w - - 0 1']
    },
    {
        'id': 4,
        'name': '估值测试',
        'fen': ['rn5r/pp2pk2/2p2npb/3P1b2/7p/2N2Q2/PPP2PRP/R3K3 w Q - 4 17'],
    },
    {
        'id': 5,
        'name': '经典两步杀与和棋',
        'fen': ['rnb1kbnr/pppp1ppp/8/4p3/6Pq/5P2/PPPPP2P/RNBQKBNR w KQkq - 1 3',
                '6k1/8/5Q2/8/8/8/K6R/8 b - - 1 2'],
    }
]


# 获取用户展示的文案
def get_fen_dict_text() -> None:
    text = ''
    for i in range(len(fen_dict)):
        text += 'id: [{}],名称:[{}]\n'.format(fen_dict[i]['id'], fen_dict[i]['name'])
    print(text)


if __name__ == '__main__':
    print("进入估值函数测试程序\n")
    get_fen_dict_text()
    choose = input('输入需要测试的编号\n')
    choose = int(choose)
    chosen_dict = None
    try:
        chosen_dict = fen_dict[int(choose) - 1]
    except Exception as e:
        print("获取数据报错，error->", e)
        exit(-1)
    fen_list = chosen_dict['fen']
    for i in range(len(fen_list)):

        board = chess.Board(fen_list[i])
        board_list = my_chess.parse_board(board)

        if choose == 1:
            print("校验叠兵")
            res, white, black = my_chess.get_pawn_piled(board_list)
            print("叠兵为->", res)
        elif choose == 2:
            print("校验局面进程")
            res = my_chess.get_current_game_course(board_list)
            print("目前局面进程为->", res)
        elif choose == 3:
            print("判断通路兵")
            res = my_chess.parse_internal_board_info(board, fen_list[i])
            print("res->", res)

            value = my_chess.do_evaluate(board, res)
            print("估值为 ", value)
        elif choose == 4:
            res = my_chess.parse_internal_board_info(board, fen_list[i])
            value = my_chess.do_evaluate(board, res)
            print("估值为 ", value)
        elif choose == 5:
            res = my_chess.check_board_status(board)
            print(board.result())
        print('这个棋谱的棋盘为 ->\n', board)
